package com.ymatou.iapi.godmch.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.sun.org.apache.bcel.internal.generic.NEW;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.bindmchBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.RemoveCodeBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createSupplierCodeCall;
import com.ymatou.iapi.godmch.service.createmchCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.country_info;
import com.ymttest.database.model.invite_code;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.model.godmch.mch_config;
import com.ymttest.database.model.godmch.mch_configExample;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.invite_codeWapper;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 新增商户信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_createmch {
	private static createmchBean bean;
	private static createmchCall call;
	private static mch_infoWapper mchInfoWapper = new mch_infoWapper();
	private static country_infoWapper countryinfoWapper = new country_infoWapper();
	private static invite_codeWapper invitecodeWapper = new invite_codeWapper();
	private static mch_relationWapper mchrelationWapper = new mch_relationWapper();
	private static agent_typeWapper agenttypeWapper = new agent_typeWapper();
	private mch_configWapper mchconfigWapper;
	private  createmchBean bean2;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增商户信息");
	}

	@Before
	public void caseUp() {
		bean = new createmchBean();
		call = new createmchCall();
		mchconfigWapper=new mch_configWapper();
		bean2 = new createmchBean();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_001() {
		Logger.start(true, "新增商户信息,验证无邀请码(渠道商),直接注册");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);

			bean.setMchId(userId);
			bean.setCountry("KOR");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode(null);

			call.setData(bean);
			call.callService();

			checkVerify(userId, false, false);
			
			//发消息总线 mq通知商品
			MessageListBean MessageListBean = MqQueryCallService.initGodmchManage("agent_bind-"+bean.getMchId(),"agent_bind");
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});

			Logger.verifyEquals(0, joa.size(), "验证总线消息content为空");
			// 创建商户发MQ 目的是新创建商户 现在有默认风控
			MessageListBean = MqQueryCallService.initGodmchManage(String.valueOf(bean.getMchId()),"mch_add");
			List <Map> mq_create = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				mq_create = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			  Logger.verifyEquals(mq_create.get(0).get("mchId"),bean.getMchId(), "验证消息总线商户Id MchId");
			  
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_001_1() {
		Logger.start(true, "新增商户信息,验证无邀请码(vip渠道商)");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			// 创建渠道
			bean.setMchId(userId);
			bean.setCountry("USA");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode(null);
			call.setData(bean);
			call.callService();
			// 设置渠道为代理商
			GodmchManageCallService.SetVip(userId);

			checkVerify(userId, true, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_createmch_001_2() {
		Logger.start(true, "新增商户信息,验证有邀请码(海外纯渠道的邀请码，邀请的商户是国外，返回继承型代理目前仅支持中国大陆商户)");//202003 修改
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 渠道商
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			createCodeBean.setAgentModel(2);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setCountry("CHN");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean2);
			call.callService();

			Logger.verifyEquals("5036", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("继承型代理目前仅支持中国大陆商户"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_001_3() {
		Logger.start(true, "新增商户信息,验证有邀请码(海外纯渠道的邀请码，邀请的商户是国内大陆，返回成功)");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 渠道商
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
		//	createCodeBean.setAgentModel(2);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("CHN");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean2);
			call.callService();
			checkVerify(userId1, false, false);
//			Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
//			Logger.verifyEquals(true, call.getMessage().contains("继承型代理目前仅支持中国大陆商户"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_002() {
		Logger.start(true, "新增商户信息,验证有邀请码(纯代理商,不可以发展下线)-代理商与渠道商计算币种一致,国家编号是国外,代理角色 数据库中的channls=1");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());

			call.setData(bean2);
			call.callService();
			checkVerify(userId1, false, false, userId2);

			//发消息总线 mq通知商品
			MessageListBean MessageListBean = MqQueryCallService.initGodmchManage("agent_bind-"+bean2.getMchId()+"-"+bean.getMchId(),"agent_bind");
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});

			Logger.verifyEquals(String.valueOf(bean.getMchId()), joa.get(0).get("parentUserId").toString(), "验证总线消息parentUserId");
			Logger.verifyEquals(String.valueOf(bean2.getMchId()), joa.get(0).get("userId").toString(), "验证总线消息userId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_002_1() {
		Logger.start(true, "新增商户信息,验证有邀请码(纯代理商,不可以发展下线)-代理商与渠道商计算币种不一致(现在返回成功 跨国20191023修改)");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 渠道商
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("CAN");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean2);
			call.callService();
			
			checkVerify(userId1, false, false, userId2);

//			Logger.verifyEquals("5015", call.getStatusCode1(), "验证返回成功status值");
//			Logger.verifyEquals(true, call.getMessage().contains("国家信息有误"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_002_4() {
		Logger.start(true, "新增商户信息,验证有邀请码(纯代理商,不可以发展下线)-国家编号是国内,代理角色 数据库中的channls=0");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("CHN");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());

			call.setData(bean2);
			call.callService();
			checkVerify(userId1, false, true, userId2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_002_2() {
		Logger.start(true, "新增商户信息,验证有邀请码(代理商,可以发展下线)-国家编号是国外,代理角色 数据库中的channls=1");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			// 设置vip
			GodmchManageCallService.SetVip(userId1);

			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());

			call.setData(bean2);
			call.callService();
			
			checkVerify(userId1, true, true, userId2);
			Logger.comment("userId1:"+userId1);
			Logger.comment("userId2:"+userId2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_002_2_2() {
		Logger.start(true, "新增商户信息,验证有邀请码(代理商,可以发展下线)-国家编号是国内,代理角色 数据库中的channls=0，国内代理发展 国内代理");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			// 设置vip
			GodmchManageCallService.SetVip(userId1);

			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("CHN");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());

			call.setData(bean2);
			call.callService();
			
			// 代理
			// 渠道商邀请码
			CreateCodeBean createCodeBean2 = GodmchManageCallService.InitcreateCodeBeanForAgent(userId2);
			CreateCodeCall createcall2 = GodmchManageCallService.createCodeCall(createCodeBean2);
			
			createmchBean bean3 = new createmchBean();
			int userId3 = GodmchManageCallService.UserCreateAgent();
			bean3.setMchId(userId3);
			bean3.setCountry("CHN");
			bean3.setCode(createcall2.getCode());
			bean3.setNickName("代理昵称_" + TestDataManager.getPhoneNum());

			call.setData(bean3);
			call.callService();
			
			checkVerify(userId1, true, true, userId2);
			Logger.comment("国内代理发展 国内代理");
			//checkVerify(userId2, true, true, userId3);
			
			Logger.comment("userId1:"+userId1);
			Logger.comment("userId2:"+userId2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_002_3() {
		Logger.start(true, "新增商户信息,验证有邀请码(代理商,可以发展下线)-国家编号是国内,代理角色 数据库中的channls=0");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			// 设置vip
			GodmchManageCallService.SetVip(userId1);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("CHN");// 货币与渠道不一致
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());

			call.setData(bean2);
			call.callService();
			checkVerify(userId1, true, false, userId2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_002_5() {
		Logger.start(true, "新增商户信息,验证 纯代理商+渠道商-绑定接口验证");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			int userId_agent = GodmchManageCallService.UserCreateAgent();
			// 渠道1
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			// 渠道2
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId_agent);
			GodmchManageCallService.createmchCallForChannel(bean);

			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 渠道1 绑定 渠道2
			bindmchBean bindbean = GodmchManageCallService.InitbindmchBean(userId_agent, createcall.getCode());
			GodmchManageCallService.bindmchcall(bindbean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_004() {
		Logger.start(true, "新增商户信息,验证有邀请码(代理商)-邀请码无效-返回错误，邀请码无效");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);

			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			bean2.setCode(createcall.getCode() + 99999);// 不存在的邀请码
			call.setData(bean2);
			call.callService();

			Logger.verifyEquals("5011", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("邀请码不存在"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_005() {
		Logger.start(true, "新增商户信息,验证商户id已经存在，再直接注册，返回错误(此接口可能不考虑,到时候看具体实现)");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			bean.setMchId(userId);
			// bean.setCode(null);
			bean.setCountry("USA");
			bean.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();
			call.callService();

			Logger.verifyEquals("5014", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("商户已存在"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_006() {
		Logger.start(true, "新增商户信息,验证商户id已经存在，再扫邀请码，返回错误(此接口可能不考虑,到时候看具体实现)");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 渠道商
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean2);
			call.callService();
			call.callService();
			Logger.verifyEquals("5014", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("商户已存在"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_createmch_007() {
		Logger.start(true, "新增商户信息,验证商户Id不存在,返回错误");
		try {
			// UserCreateBean
			// usercreateBean=DGUserCallService.initUsercreateBean();
			// int userId=DGUserCallService.UserCreateCall(usercreateBean);
			bean.setMchId(null);
			// bean.setCode(null);
			bean.setCountry("USA");
			bean.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();

			Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("商户已存在"), "商户id不能为空");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_008() {
		Logger.start(true, "新增商户信息,验证邀请码不存在,返回错误");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 渠道商
			bean.setMchId(userId1);
			bean.setCountry("USA");
			bean.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			bean2.setCode(createcall.getCode() + 1);// 邀请码不存在
			call.setData(bean2);
			call.callService();

			Logger.verifyEquals("5011", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("邀请码不存在"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_009() {
		Logger.start(true, "新增商户信息,验证国家码不存在,返回错误");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 渠道商
			bean.setMchId(userId1);
			bean.setCountry("aaaa");
			bean.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();

			Logger.verifyEquals("5015", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("国家信息有误"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_010() {
		Logger.start(true, "新增商户信息,验证商户id已经是客服(渠道是别的商户客服，再创建渠道)，再扫邀请码，返回错误");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId_channl = DGUserCallService.UserCreateCall(usercreateBean);
			// 渠道商
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(bean);
			// csid
			usercreateBean = DGUserCallService.initCsUsercreateBean();
			int csId = DGUserCallService.UserCreateCall(usercreateBean);
			GodmchManageCallService.CreateCSCall(userId_channl, csId, 4);

			bean.setMchId(csId);
			bean.setCountry("USA");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode(null);
			call.setData(bean);
			call.callService();
			Logger.verifyEquals("5013", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("客服只能是单一角色，不能同时为代理或渠道商或者是直销商"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_011() {
		Logger.start(true, "新增商户信息,验证商户id为空，返回错误");
		try {
			bean.setMchId(null);
			bean.setCountry("USA");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();

			Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("商户id不能为空"), "商户id不能为空");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_createmch_012() {
		Logger.start(true, "新增商户信息,验证邀请码为空，返回错误");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 渠道商
			bean.setMchId(userId1);
			bean.setCountry("USA");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setCode(null);// 邀请码为空
			call.setData(bean2);
			call.callService();

			Logger.verifyEquals("5011", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("邀请码为空"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_013() {
		Logger.start(true, "新增商户信息,验证国家码为空，返回错误");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			bean.setMchId(userId);
			// bean.setCountry("USA");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();

			Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("国家码不能为空"), "验证返回成功msg值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	//@Ignore
	public void Tc_createmch_014() {
		Logger.start(true, "新增商户信息,验证有邀请码(代理商)-三级代理-b是a的代理商，c是b的代理商，c是a的代理商,返回正常 -绑定接口验证");
		try {
			// 1,2:先创建a,b渠道
			// 3:b代理c
			// 4:a绑定代理b
			// 5:a绑定代理c

			// 1:渠道商 a
			Logger.comment("###### 1:渠道商 a ##############");
			int userId_a = GodmchManageCallService.UserCreateAgent();// a
			bean.setMchId(userId_a);
			bean.setCountry("USA");
			bean.setNickName("自动化测试昵称_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
			// 渠道商 a 邀请码
			Logger.comment("###### 渠道商 a 邀请码 ##############");
			CreateCodeBean createCodeBean_a = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_a);
			CreateCodeCall createcall_a = GodmchManageCallService.createCodeCall(createCodeBean_a);
			// 2:渠道商b
			Logger.comment("###### 渠道商b #############");
			int userId_b = GodmchManageCallService.UserCreateAgent();// b
			bean.setMchId(userId_b);
			bean.setCountry("USA");
			bean.setNickName("自动化测试昵称_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
			// 渠道商 b邀请码
			Logger.comment("###### 渠道商 b邀请码 ##############");
			CreateCodeBean createCodeBean_b = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_b);
			CreateCodeCall createcall_b = GodmchManageCallService.createCodeCall(createCodeBean_b);
			// 3:b代理c
			Logger.comment("###### b代理c ##############");
			int userId_c = GodmchManageCallService.UserCreateAgent();
			createmchBean bean3 = new createmchBean();
			bean3.setMchId(userId_c);
			bean3.setCountry("USA");
			bean3.setNickName("自动化测试昵称_"+TestDataManager.getRandomIntNum(5));
			bean3.setCode(createcall_b.getCode());
			call.setData(bean3);
			call.callService();

			// 4:a绑定代理b
			Logger.comment("###### a绑定代理b ##############");
			bindmchBean bindmchbean_ab = GodmchManageCallService.InitbindmchBean(userId_b, createcall_a.getCode());
			GodmchManageCallService.bindmchcall(bindmchbean_ab);
			// 5:a绑定代理c
			Logger.comment("###### a绑定代理c ##############");
			bindmchBean bindmchbean_ac = GodmchManageCallService.InitbindmchBean(userId_c, createcall_a.getCode());
			GodmchManageCallService.bindmchcall(bindmchbean_ac);
//			// 验证 mch_info表中的 b是代理+渠道 agent=1 && channel=1
//			org.junit.Assert.fail();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_createmch_015() {
		Logger.start(true, "新增商户信息,验证渠道商国家编号不能国内(CHN)-返回错误");
		try {
			int userId = GodmchManageCallService.UserCreateAgent();
			bean.setMchId(userId);
			bean.setCountry("CHN");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();
			Logger.verifyEquals("5025", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("渠道商必须拥有海外资质"), "验证返回成功msg值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_createmch_016() {
		Logger.start(true, "新增商户信息,验证有邀请码(代理商)-三级代理-b是a的代理商，c是b的代理商，a是c的代理商,返回错误");
		try {
			// 1,2:先创建a,b渠道
			// 3:b代理c
			// 4:a绑定代理b
			// 5:a绑定代理c

			// 1:渠道商 a
			Logger.comment("###### 1:渠道商 a ##############");
			int userId_a = GodmchManageCallService.UserCreateAgent();// a
			bean.setMchId(userId_a);
			bean.setCountry("USA");
			bean.setNickName(TestDataManager.getRandomNum(5));
			call.setData(bean);
			call.callService();
			// 渠道商 a 邀请码
			Logger.comment("###### 渠道商 a 邀请码 ##############");
			CreateCodeBean createCodeBean_a = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_a);
			CreateCodeCall createcall_a = GodmchManageCallService.createCodeCall(createCodeBean_a);
			// 2:渠道商b
			Logger.comment("###### 渠道商b #############");
			int userId_b = GodmchManageCallService.UserCreateAgent();// b
			bean.setMchId(userId_b);
			bean.setCountry("USA");
			bean.setNickName(TestDataManager.getRandomNum(5));
			call.setData(bean);
			call.callService();
			// 渠道商 b邀请码
			Logger.comment("###### 渠道商 b邀请码 ##############");
			CreateCodeBean createCodeBean_b = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_b);
			CreateCodeCall createcall_b = GodmchManageCallService.createCodeCall(createCodeBean_b);

			
			// 3:b代理c
			Logger.comment("###### b代理c ##############");
			int userId_c = GodmchManageCallService.UserCreateAgent();
			createmchBean bean3 = new createmchBean();
			bean3.setMchId(userId_c);
			bean3.setCountry("USA");
			bean3.setNickName(TestDataManager.getRandomNum(5));
			bean3.setCode(createcall_b.getCode());
			call.setData(bean3);
			call.callService();
			
			
			
						

			Logger.comment("纯代理商禁止创建邀请码，通过不了");
			CreateCodeBean createCodeBean_c = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_c);
			CreateCodeCall createcall_c = GodmchManageCallService.createCodeCall(createCodeBean_c);

			// 4:a绑定代理b
			Logger.comment("###### a绑定代理b ##############");
			bindmchBean bindmchbean_ab = GodmchManageCallService.InitbindmchBean(userId_b, createcall_a.getCode());
			GodmchManageCallService.bindmchcall(bindmchbean_ab);
			// 5:c绑定代理a
			Logger.comment("###### c绑定代理a ##############");
			bindmchBean bindmchbean_ac = GodmchManageCallService.InitbindmchBean(userId_a, createcall_c.getCode());
			GodmchManageCallService.bindmchcall(bindmchbean_ac);
			org.junit.Assert.fail();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_018() {
		Logger.start(true, "新增商户信息,验证vip渠道 代理,vip代理 再代理三级代理-vip a代理vip b,vip b代理 vip c,返回正确");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			
			GodmchManageCallService.createmchCallForChannel(bean);
			// 设置vip
			GodmchManageCallService.SetVip(userId1);

			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理1
			bean = new createmchBean();
			int userId_agent1 = GodmchManageCallService.UserCreateAgent();
			bean.setMchId(userId_agent1);
			bean.setCountry("USA");
			bean.setCode(createcall.getCode());
			bean.setNickName("自动化测试代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();
			// 代理1邀请码
			createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_agent1);
			createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			checkVerify(userId1, true, false, userId_agent1);

			// 代理2
			int userId_agent2 = GodmchManageCallService.UserCreateAgent();
			bean.setMchId(userId_agent2);
			bean.setCountry("USA");
			bean.setCode(createcall.getCode());
			bean.setNickName("自动化测试代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();
			// 代理2邀请码
			createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_agent2);
			createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			checkVerify(userId1, true, false, userId_agent2);

			// 代理3
			int userId_agent3 = GodmchManageCallService.UserCreateAgent();
			bean.setMchId(userId_agent3);
			bean.setCountry("USA");
			bean.setCode(createcall.getCode());
			bean.setNickName("自动化测试代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean);
			call.callService();

			checkVerify(userId1, true, false, userId_agent3);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	// 验证货币信息
	public void Tc_createmch_019() {
		Logger.start(true, "新增商户信息,验证所有国家和对应货币数据落地信息");
		try {
			countryinfoWapper.selectAllCountryInfo().forEach(ci -> {
				try {
					//中国大陆只能注册代理商
					if (!ci.getCountry().equals("CHN")) {
						UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
						int userId = DGUserCallService.UserCreateCall(usercreateBean);
						bean.setMchId(userId);
						bean.setCountry(ci.getCountry());
						bean.setNickName(String.valueOf(YMTDateUtil.getDate().getTime()));
						bean.setCode(null);
						call.setData(bean);
						call.callService();
						Map<String, Object> map = new HashMap();
						map.put("mchId", userId);
						mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
						// 获取国家编号
						country_info countryinfo = countryinfoWapper.selectByPrimaryKey(bean.getCountry());
						Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
						Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
						Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
						Logger.verifyEquals(bean.getCountry(), mchInfo.getCountry(), "验证数据库mch_info对应的字段Country");
						Logger.verifyEquals(countryinfo.getCurrency(), mchInfo.getCurrency(), "验证数据库mch_info对应的字段Currency");
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			});
			;
			// UserCreateBean
			// usercreateBean=DGUserCallService.initUsercreateBean();
			// int userId=DGUserCallService.UserCreateCall(usercreateBean);
			//
			// bean.setMchId(userId);
			// bean.setCountry("USA");
			// bean.setNickName("商户昵称_"+TestDataManager.getPhoneNum());
			// bean.setCode(null);
			//
			// call.setData(bean);
			// call.callService();
			//
			// checkVerify(userId,false,false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	
	@Test
	@Category({ P1.class }) 
	@TestCase
	public void Tc_createmch_020() {
		Logger.start(true, "新增商户信息,验证有邀请码(国外代理)-渠道支付类型是盛付通-代理非盛付通");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			//设置渠道支付类型是盛付通
			GodmchManageCallService.SetPayMode(userId1);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());

			call.setData(bean2);
			call.callService();
			
			//checkVerify(userId1, false, false, userId2);
			
			// 获取客服信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", userId1);
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
			// 获取国家编号
			country_info countryinfo = countryinfoWapper.selectByPrimaryKey(bean.getCountry());
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			Logger.verifyEquals(bean.getCountry(), mchInfo.getCountry(), "验证数据库mch_info对应的字段Country");
			Logger.verifyEquals(countryinfo.getCurrency(), mchInfo.getCurrency(), "验证数据库mch_info对应的字段Currency");

			Logger.verifyEquals(0, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip");
			Logger.verifyEquals(0, mchInfo.getState(), "验证数据库mch_info对应的字段State");
			Logger.verifyNotNull(mchInfo.getCreateTime(), "验证数据库mch_info对应的字段CreateTime");
			Logger.verifyNotNull(mchInfo.getUpdateTime(), "验证数据库mch_info对应的字段UpdateTime");
			if (mchInfo.getAgent() == 1)// 代理
			{
				// mch_info
				
			    Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");

				Logger.verifyEquals(1, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
				// mch_relation
				List<mch_relation> mchrelations = mchrelationWapper.selectByPrimaryKey(userId2, userId1);
				for (mch_relation relation : mchrelations) {
					// agent_type
					Map<String, Object> map2 = new HashMap();
					map2.put("mchId", relation.getParentMchId());
					map2.put("agentType", relation.getAgentType());
					List<agent_type> agenttypeList = agenttypeWapper.selectby(map);
					Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
					// invite_code
					Map<String, Object> map3 = new HashMap();
					map3.put("mchId", relation.getParentMchId());
					map3.put("inviteCode", relation.getInviteCode());
					List<invite_code> inviteCodeList = invitecodeWapper.selectby(map3);
					Logger.verifyEquals(true, inviteCodeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段inviteCode 存在");	
				}

			} else// 渠道
			{
				Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");
				Logger.verifyEquals(0, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
			}
			//支付方式 新增20191014 
			Logger.verifyEquals(3, mchInfo.getPayMode(), "验证数据库mch_info对应的字段PayMode");
			//支付宝支付方式 新增20191224
			Logger.verifyEquals(0,mchInfo.getAliPayMode(), "验证AliPayMode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class }) 
	@TestCase
	public void Tc_createmch_020_1() {
		Logger.start(true, "新增商户信息,验证有邀请码(国内代理)-渠道支付类型是盛付通-代理非盛付通");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			bean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(bean);
			//设置渠道支付类型是盛付通
			GodmchManageCallService.SetPayMode(userId1);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("CHN");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());

			call.setData(bean2);
			call.callService();
			
			//checkVerify(userId1, false, false, userId2);

			
			// 获取客服信息
			Map<String, Object> map = new HashMap();
			map.put("mchId", userId1);
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
			// 获取国家编号
			country_info countryinfo = countryinfoWapper.selectByPrimaryKey(bean.getCountry());
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			Logger.verifyEquals(bean.getCountry(), mchInfo.getCountry(), "验证数据库mch_info对应的字段Country");
			Logger.verifyEquals(countryinfo.getCurrency(), mchInfo.getCurrency(), "验证数据库mch_info对应的字段Currency");

			Logger.verifyEquals( 0, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip");
			Logger.verifyEquals(0, mchInfo.getState(), "验证数据库mch_info对应的字段State");
			Logger.verifyNotNull(mchInfo.getCreateTime(), "验证数据库mch_info对应的字段CreateTime");
			Logger.verifyNotNull(mchInfo.getUpdateTime(), "验证数据库mch_info对应的字段UpdateTime");
			if (mchInfo.getAgent() == 1)// 代理
			{
			
				Logger.verifyEquals(0, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");

				Logger.verifyEquals(1, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
				// mch_relation
				List<mch_relation> mchrelations = mchrelationWapper.selectByPrimaryKey(userId2, userId1);
				for (mch_relation relation : mchrelations) {
					// agent_type
					Map<String, Object> map2 = new HashMap();
					map2.put("mchId", relation.getParentMchId());
					map2.put("agentType", relation.getAgentType());
					List<agent_type> agenttypeList = agenttypeWapper.selectby(map);
					Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
					// invite_code
					Map<String, Object> map3 = new HashMap();
					map3.put("mchId", relation.getParentMchId());
					map3.put("inviteCode", relation.getInviteCode());
					List<invite_code> inviteCodeList = invitecodeWapper.selectby(map3);
					Logger.verifyEquals(true, inviteCodeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段inviteCode 存在");
					
					
				}

			} else// 渠道
			{
				Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");
				Logger.verifyEquals(0, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
			}

			//支付方式 新增20191014 
			Logger.verifyEquals(3, mchInfo.getPayMode(), "验证数据库mch_info对应的字段PayMode");
			//支付宝支付方式 新增20191224
			Logger.verifyEquals(0,mchInfo.getAliPayMode(), "验证AliPayMode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_021() {
		Logger.start(true, "新增商户信息,验证不支持本土(AUS)-商户所在的国家如果不支持本国币种结算，落地USD，否则落地对应国家币种");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			// 创建渠道
			bean.setMchId(userId);
			bean.setCountry("AUS");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode(null);
			call.setData(bean);
			call.callService();

			checkVerify(userId, false, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_022() {
		Logger.start(true, "新增商户信息,验证支持本土(AUS)-商户所在的国家如果不支持本国币种结算，落地USD，否则落地对应国家币种");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			// 创建渠道
			bean.setMchId(userId);
			bean.setCountry("BEL");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode(null);
			call.setData(bean);
			call.callService();

			checkVerify(userId, false, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_023() {
		Logger.start(true, "新增商户信息,验证有邀请码(国内身份商专属邀请码(disconfig配置GNQDS)注册为渠道商，无代理商身份)");
		try {

			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);

			bean.setMchId(userId);
			bean.setCountry("CHN");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode("GNQDS1");

			call.setData(bean);
			call.callService();

			checkVerify(userId, false, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_023_1() {
		Logger.start(true, "新增商户信息,验证有专属邀请码GNQDS-country=USA-失败");
		try {

			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);

			bean.setMchId(userId);
			bean.setCountry("USA");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode("GNQDS1");

			call.setData(bean);
			call.callService();

			Logger.verifyEquals("5011", call.getStatusCode1(), "验证专属邀请码不支持国外");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_023_2() {
		Logger.start(true, "新增商户信息,验证有专属邀请码gnqds 小写");
		try {

			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);

			bean.setMchId(userId);
			bean.setCountry("CHN");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode("gnqds1");

			call.setData(bean);
			call.callService();

			checkVerify(userId, false, false);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_024() {
		Logger.start(true, "新增商户信息,验证专属邀请码注册为国内渠道商-发展下级国外代理");
		try {
            //国内渠道
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			
			bean.setMchId(userId);
			bean.setCountry("CHN");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode("GNQDS");

			call.setData(bean);
			call.callService();
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("USA");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean2);
			call.callService();
			Logger.comment("userId:"+userId);
			Logger.comment("userId2:"+userId2);
			checkVerify(userId, false, false,userId2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_025() {
		Logger.start(true, "新增商户信息,验证专属邀请码注册为国内渠道商-发展下级国内代理");
		try {
            //国内渠道
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			
			bean.setMchId(userId);
			bean.setCountry("CHN");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode("GNQDS");

			call.setData(bean);
			call.callService();
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			int userId2 = GodmchManageCallService.UserCreateAgent();
			bean2.setMchId(userId2);
			bean2.setCountry("CHN");
			bean2.setCode(createcall.getCode());
			bean2.setNickName("代理昵称_" + TestDataManager.getPhoneNum());
			call.setData(bean2);
			call.callService();
			Logger.comment("userId:"+userId);
			Logger.comment("userId2:"+userId2);
			checkVerify(userId, false, false,userId2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_createmch_026() {
		Logger.start(true, "新增商户信息,验证独立供货商邀请码注册平台商户-返回失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);

			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            
			createSupplierCodeCall createSupplierCodeCall=GodmchManageCallService.createSupplierCode(createIndepMchCall.getmchId());
			
			bean.setMchId(userId);
			bean.setCountry("USA");
			bean.setNickName("商户昵称_" + TestDataManager.getPhoneNum());
			bean.setCode(createSupplierCodeCall.getCode());

			call.setData(bean);
			call.callService();

			Logger.verifyEquals("5011", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("邀请码不存在", call.getMessage(), "验证返回成功Message值");
			  
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	/**
	 * 
	 * @param userId_channl
	 *            渠道id
	 * @param isVip
	 *            是否是vip
	 * @param isCurrency
	 *            渠道商为国外货币,代理是否为国内
	 * @param userId_agent
	 *            代理用户
	 * @throws InterruptedException
	 * @throws JSONException
	 */
	private void checkVerify(int userId_channl, boolean isVip, boolean isCHN, int... userId_agent) throws InterruptedException, JSONException {
		// 获取客服信息
		Map<String, Object> map = new HashMap();
		map.put("mchId", userId_channl);
		mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
		// 获取国家编号
		country_info countryinfo = countryinfoWapper.selectByPrimaryKey(bean.getCountry());
		Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
		Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
		Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
		Logger.verifyEquals(bean.getCountry(), mchInfo.getCountry(), "验证数据库mch_info对应的字段Country");
		Logger.verifyEquals(countryinfo.getCurrency(), mchInfo.getCurrency(), "验证数据库mch_info对应的字段Currency");

		Logger.verifyEquals(isVip == true ? 1 : 0, mchInfo.getVip(), "验证数据库mch_info对应的字段Vip");
		Logger.verifyEquals(0, mchInfo.getState(), "验证数据库mch_info对应的字段State");
		Logger.verifyNotNull(mchInfo.getCreateTime(), "验证数据库mch_info对应的字段CreateTime");
		Logger.verifyNotNull(mchInfo.getUpdateTime(), "验证数据库mch_info对应的字段UpdateTime");
		if (mchInfo.getAgent() == 1)// 代理
		{
			// mch_info
			if (isCHN == true)
				Logger.verifyEquals(0, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");
			else
				Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");

			Logger.verifyEquals(1, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
			// mch_relation
			List<mch_relation> mchrelations = mchrelationWapper.selectByPrimaryKey(userId_agent[0], userId_channl);
			for (mch_relation relation : mchrelations) {
				// agent_type
				Map<String, Object> map2 = new HashMap();
				map2.put("mchId", relation.getParentMchId());
				map2.put("agentType", relation.getAgentType());
				List<agent_type> agenttypeList = agenttypeWapper.selectby(map);
				Logger.verifyEquals(true, agenttypeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段agentType 存在");
				// invite_code
				Map<String, Object> map3 = new HashMap();
				map3.put("mchId", relation.getParentMchId());
				map3.put("inviteCode", relation.getInviteCode());
				List<invite_code> inviteCodeList = invitecodeWapper.selectby(map3);
				Logger.verifyEquals(true, inviteCodeList.size() > 0, "验证数据库mch_relation对应的 一级代理 字段inviteCode 存在");
			}
            //代理 
			map = new HashMap();
			map.put("mchId", userId_agent[0]);
			mch_info mchInfo_agent = mchInfoWapper.selectby(map).get(0);
			Logger.verifyEquals(true,bean2.getCountry()=="CHN"?mchInfo_agent.getChannels()==0:mchInfo_agent.getChannels()==1, "验证channels");
			Logger.verifyEquals(1,mchInfo_agent.getAgent(), "验证Agent");
			
		} else// 渠道
		{
			Logger.verifyEquals(1, mchInfo.getChannels(), "验证数据库mch_info对应的字段Channel");
			Logger.verifyEquals(0, mchInfo.getAgent(), "验证数据库mch_info对应的字段Agent");
		}

		//支付方式 新增20191014 
		Logger.verifyEquals(2, mchInfo.getPayMode(), "验证数据库mch_info对应的字段PayMode");
		//支付宝支付方式 新增20191224
		Logger.verifyEquals(0,mchInfo.getAliPayMode(), "验证AliPayMode");
		//新增 风控 20200227 summing
        mch_configExample example=new mch_configExample();
        example.createCriteria().andMchIdEqualTo(bean.getMchId());
        List<mch_config> mchconfigs=mchconfigWapper.selectByExample(example);
        if(mchconfigs.size()>0)
        {
        	mch_config mchconfig=mchconfigs.get(0);
	        //新增加商户默认风控值
	        String productRiskAmount=EnvSetup.getData("productRiskAmount");
	        String tradeRiskAmount=EnvSetup.getData("tradeRiskAmount");
	        Logger.verifyEquals(mchconfig.getProductRiskAmount().stripTrailingZeros().toPlainString(),productRiskAmount, "验证数据库mch_confog 中字段ProductRiskAmount与传入的ProductRiskAmount是否一致");
	        Logger.verifyEquals(mchconfig.getTradeRiskAmount().stripTrailingZeros().toPlainString(),tradeRiskAmount, "验证数据库mch_confog 中字段TradeRiskAmount与传入的TradeRiskAmount是否一致");
        }
        //结算币种 新增 20200407 商户所在的国家如果不支持本国币种结算，落地USD，否则落地对应国家币种
        Logger.verifyEquals(countryinfo.getSupportLocalCurrency()!=1?"USD":countryinfo.getCurrency(),mchInfo.getSettlementCurrency(),"验证数据库mch_info对应的字段settlementCurrency(商户所在的国家如果不支持本国币种结算，落地USD，否则落地对应国家币种)");
      
        if(bean.getCode()!=null && bean.getCode().equals("GNQDS"))
        {
        	Logger.verifyEquals(2, mchInfo.getMchShareType(), "验证国内渠道商的店铺分享类型为H5");
        	Logger.verifyEquals(2, mchInfo.getPayMode(), "验证国内渠道商的payMode为飞界国际电子商务");
        	Logger.verifyEquals(1, mchInfo.getDomesticPayMode(), "所有商户的国内支付通道默认都设置为盛付通-海鲲科技");
        }
        
	}
}